<?php
$adimg_list=array();
$sql="SELECT ap.ad_width,ap.ad_height, ad.ad_id, ad.ad_name,ad.ad_code, ad.ad_link , abs(substring(position_name,10)) as pnid ".
	" from ".$GLOBALS['ecs']->table('ad_position').
		" as ap left join ".$GLOBALS['ecs']->table('ad')." as ad on ad.position_id = ap.position_id ".
		" where ap.position_name like '首页幻灯片-大图%' and ad.media_type=0 ".
		" and UNIX_TIMESTAMP()>ad.start_time and UNIX_TIMESTAMP()<ad.end_time and ad.enabled=1 ".
	       " ORDER BY pnid ASC limit 0,10 ";
$res_adimg = $GLOBALS['db']->query($sql);
$num=1;
while ( $row_adimg = $GLOBALS['db']->fetchRow($res_adimg) )
{
	$row_adimg['num']=$num;
	$row_adimg['href'] = "affiche.php?ad_id=" . $row_adimg[ad_id] . "&amp;uri=" . urlencode($row_adimg['ad_link']);
	$row_adimg['src'] = "data/afficheimg/". $row_adimg['ad_code'];

	//三个小图
	$sql="SELECT ap.ad_width,ap.ad_height, ad.ad_id, ad.ad_name,ad.ad_code, ad.ad_link  ".
	" from ".$GLOBALS['ecs']->table('ad_position').
		" as ap left join ".$GLOBALS['ecs']->table('ad')." as ad on ad.position_id = ap.position_id ".
		" where ap.position_name = '首页幻灯片-小图-". $row_adimg['pnid'] ."' and ad.media_type=0 ".
		" and UNIX_TIMESTAMP()>ad.start_time and UNIX_TIMESTAMP()<ad.end_time and ad.enabled=1 ".
	       " ORDER BY ad_id ASC limit 0,3 ";
	$res_smallimg = $GLOBALS['db']->query($sql);
	$smallimg_list=array();
        while ($row_smallimg = $GLOBALS['db']->fetchRow($res_smallimg) )
	{
			$row_smallimg['href'] = "affiche.php?ad_id=" . $row_smallimg[ad_id] . "&amp;uri=" . urlencode($row_smallimg['ad_link']);
			$row_smallimg['src'] = "data/afficheimg/". $row_smallimg['ad_code'];
			$smallimg_list[] = $row_smallimg;
	}		
	if(!$smallimg_list)
	{
		$smallimg_list[0]=array("href"=>"#",'src'=>"data/smallimg_blank.gif","ad_width"=>'222',"ad_height"=>'160');
		$smallimg_list[1]=array("href"=>"#",'src'=>"data/smallimg_blank.gif","ad_width"=>'222',"ad_height"=>'160');
		$smallimg_list[2]=array("href"=>"#",'src'=>"data/smallimg_blank.gif","ad_width"=>'222',"ad_height"=>'160');
	}
	$row_adimg['smallimg_list']  = $smallimg_list;

	$adimg_list[] = $row_adimg;
	$num++;
}
$bannercount=$num-2;
print_r($adimg_lis);
$GLOBALS['smarty']->assign('adimg_list', $adimg_list);
$GLOBALS['smarty']->assign('bannercount', $bannercount);
?>
<style>
.blank{height:8px; line-height:8px; clear:both; visibility:hidden;}
.slide-box{float:left;width:666px; height:420px; margin-bottom:10px;  float:left; position:relative}
.slide-box .slide-img{overflow:hidden;height:400px;width:666px; display:block;}
.slide-box .slide-img img{display:inline;padding:0;margin:0;overflow:hidden;}
.slide-box .slide-img ul{padding:0;margin:0;}
.slide-box .slide-img li{padding:0;margin:0;}
.slide-box .slide-img li table{padding:0;margin:0;}
.slide-box .slide-img li table td{padding:0;margin:0;}
.slide-num{height:22px; width:666px; padding:4px 10px;position:absolute; bottom:0; right:0px; z-index:30; background:#EEE;}
.slide-num ul{margin:0;padding:0;list-style-type:0;float:right;}
.slide-num li{display:block; float:left; background:#999;margin-left:5px; width:25px; height:22px;cursor:pointer;text-align:center;color:#fff;}
.slide-num span{display:block; float:right; padding-left:5px;width:19px; height:20px}
.slide-num  .nonce{background:#c00;}
.slide-box a{color:#fff;}
.slide-num li a{display:inline;line-height:22px;color:#fff;font-size:13px;text-align:center;}

</style>
<div class="slide-box" >
      <div class="slide-num" id="myTab_btns2">
          <ul>
	  <?php $_from = $this->_var['adimg_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'adimg');$this->_foreach['adimg_list'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['adimg_list']['total'] > 0):
    foreach ($_from AS $this->_var['adimg']):
        $this->_foreach['adimg_list']['iteration']++;
?>
	   <li  <?php if ($this->_foreach['adimg_list']['iteration'] == 1): ?>class="nonce"<?php endif; ?>><a href="#"><font color=#ffffff><?php echo $this->_var['adimg']['num']; ?></font></a></li>
          <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
	  </ul>
      </div>
	<div class="slide-img" id="slidemain">
	
        <ul>
	<?php $_from = $this->_var['adimg_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'slide');$this->_foreach['adimg_list'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['adimg_list']['total'] > 0):
    foreach ($_from AS $this->_var['slide']):
        $this->_foreach['adimg_list']['iteration']++;
?>
	<li>
	<table cellpadding=0 cellspacing=0 width="100%">
	<tr><td colspan=3 width="100%"><a href="<?php echo $this->_var['slide']['href']; ?>" target="_blank"><img width="<?php echo $this->_var['slide']['ad_width']; ?>" height="<?php echo $this->_var['slide']['ad_height']; ?>" src="<?php echo $this->_var['slide']['src']; ?>">
	</a>
	</td></tr>
	<tr>
	<?php $_from = $this->_var['slide']['smallimg_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'small');$this->_foreach['smallimg_list'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['smallimg_list']['total'] > 0):
    foreach ($_from AS $this->_var['small']):
        $this->_foreach['smallimg_list']['iteration']++;
?>
	<td width="33%" align=left style="padding:0;margin:0;"><a href="<?php echo $this->_var['small']['href']; ?>" target="_blank"><img src="<?php echo $this->_var['small']['src']; ?>" width="<?php echo $this->_var['small']['ad_width']; ?>" height="<?php echo $this->_var['small']['ad_height']; ?>" border=0></a></td>
	<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
	</tr>
	</table>
	</li>
	<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>

	</ul>
	</div>
</div>
<div style="clear:both;"></div>
<script language="javascript">
var bannercount=<?php echo $this->_var['bannercount']; ?>;
var Ex=function (o){for(var k in o)this[k]=o[k];return this}
var UI=function (id){return document.getElementById(id)}
var UIs=function (tag){return Ex.call([],this.getElementsByTagName(tag))}
var Each=function (a,fn){for(var i=0;i<a.length;i++)fn.call(a[i],i,a)}
var dhooo=function (ini){
this.bind(ini,this);
this.autoIndex=0;
};
Ex.call(dhooo.prototype,{
bind:function (ini,me){
var dir=ini.dir=='top'?'scrollTop':'scrollLeft',pan=UI(ini.contentID);
var start=function (o){
Each(ini.btns,function(){this.className=''});
o.className=ini.className;
me.autoIndex=o.index;
me.begin(o.index,pan,ini.len,dir);
};
pan.onmouseover=function (){me.stop=true};
Each(ini.btns,function (i){
this.index=i;
this.onmouseover=function (){me.stop=true;start(this)};
pan.onmouseout=this.onmouseout=function(){me.stop=false}
});
var auto=function(){
if(!me.stop){
me.autoIndex=me.autoIndex==bannercount?0:++me.autoIndex;
start(ini.btns[me.autoIndex]);
}
};
if(ini.auto)this.autoPlay=window.setInterval(auto,4000);
}
,begin:function (i,o,len,dir){
    var img=o.getElementsByTagName("li");
    if(document.all)
        img[i].childNodes[0].childNodes[0].style.filter="alpha(opacity=0)";
    else
        img[i].style.opacity=0.05;
    var diff=(i*len-o[dir])*1;
o[dir]+=Math[diff>0?'ceil':'floor'](diff);
var opacitynum=0;
(function (me){
clearInterval(me.only);
me.only=setInterval(function (){
opacitynum+=0.05;
if(document.all)
    img[i].childNodes[0].childNodes[0].style.filter="alpha(opacity="+opacitynum*100+")";
else
img[i].style.opacity=opacitynum;
if(opacitynum>=1)clearInterval(me.only);
},10)
})(this)
}
})
if(!isIE_8()){
    if(isIE_c()){
    new dhooo({
    btns:UIs.call(UI('myTab_btns2'),'LI')
    ,className:'nonce'
    ,contentID:'slidemain'
    ,len:404
    ,dir:'top'
    ,auto:true
    });    //这里的len要比图片高度多4px
    }else{
        new dhooo({
            btns:UIs.call(UI('myTab_btns2'),'LI')
            ,className:'nonce'
            ,contentID:'slidemain'
            ,len:400
            ,dir:'top'
            ,auto:true
            });  //这里的len就是图片高度
    }
}else{
    new dhooo({
    btns:UIs.call(UI('myTab_btns2'),'LI')
    ,className:'nonce'
    ,contentID:'slidemain'
    ,len:400
    ,dir:'top'
    ,auto:true
    });   //这里的len就是图片高度
}
//ff兼容
function isIE_c(){
    if(window.navigator.userAgent.toLowerCase().indexOf("msie 8.0")>1)
        return false;
   return window.navigator.userAgent.toLowerCase().indexOf("msie")>=1?true:false;
}
function isIE_8(){
    if(window.navigator.userAgent.toLowerCase().indexOf("msie 8.0")>1)
        return true;
    else
        return false;
}
</script>